package pages

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
)

func GetClubsTable(ctx *context.Context) table.Table {

	clubs := table.NewDefaultTable(ctx, table.DefaultConfigWithDriver("mysql"))

	info := clubs.GetInfo()
	info.SetFilterFormLayout(form.LayoutFilter)

	info.AddField("Id", "id", db.Int).
		FieldSortable()
	info.AddField("名称", "name", db.Varchar).
		FieldFilterable()
	info.AddField("创建时间", "created_at", db.Timestamp).
		FieldFilterable(types.FilterType{
			FormType: form.DatetimeRange,
		})

	info.SetTable("clubs").SetTitle("社团管理").SetDescription("社团管理")

	detail := clubs.GetDetailFromInfo()
	detail.AddField("描述", "description", db.Text)

	formList := clubs.GetForm()
	formList.AddField("Id", "id", db.Int, form.Default).
		FieldDisableWhenCreate().
		FieldHide()
	formList.AddField("名称", "name", db.Varchar, form.Text).FieldMust()
	formList.AddField("描述", "description", db.Varchar, form.TextArea).FieldMust()
	formList.AddField("创建时间", "created_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenInsert()

	formList.SetTable("clubs").SetTitle("社团管理").SetDescription("社团管理")

	return clubs
}
